/*本文件为泛微个人设置页面练习所用到的js函数*/
var home,more,moreThings,logomenu,settings,main;

/*名字头像所在的user-panel的悬停事件函数*/
function userMenuOver(){
	document.getElementById("user-menu").style.display="block";
}
function userMenuOut(){
	document.getElementById("user-menu").style.display="none";
}
function menuon(){
	document.getElementById("user-menu").style.display="block";
	document.getElementsByClassName("user-panel")[0].style.backgroundColor="#02aed9";
}
function menuout(){
	document.getElementById("user-menu").style.display="none";
	document.getElementsByClassName("user-panel")[0].style.background="none";
}

function changeBody1(obj) {
	obj.className="user-menu-li user-li-selected"	;
	console.log(obj.parentElement.tagName);
	obj.parentElement.children[1].className="user-menu-li";
	document.getElementById("user-menu-body1").style.visibility="visible";
	document.getElementById("user-menu-body2").style.visibility="hidden";
}
function changeBody2(obj) {
	console.log("1");	
	obj.className="user-menu-li user-li-selected"	;	
	obj.parentElement.children[0].className="user-menu-li";
	document.getElementById("user-menu-body1").style.visibility="hidden";
	document.getElementById("user-menu-body2").style.visibility="visible";
}
/*home图标的悬停事件函数*/
function homeOver(){
	home=document.getElementById("dropdown-menu-home");
	home.style.display="block";
}
function homeOut(){
	home.style.display="none";
	home.parentNode.style.background="none";
}
function homeMenuOver(){
	home.parentNode.style.background="#02aed9";
}

/*导航栏更多应用相关函数*/
function moreOver(){
	more = document.getElementById("dropdown-menu-more");
	more.style.display="block";
	more.parentNode.style.backgroundColor="#fff";
	more.parentNode.children[0].style.color="#48484e";
	more.parentNode.children[0].firstChild.style.display="none";
}
function moreOut(){
	more.style.display="none";
	more.parentNode.style.background="none";
	more.parentNode.children[0].style.color="#fff";
	more.parentNode.children[0].firstChild.style.display="block";
}
function moreMenuOver(){
	more.parentNode.style.backgroundColor="#fff";
	more.parentNode.children[0].style.color="#48484e";
	more.parentNode.children[0].firstChild.style.display="none";
}


/*导航栏加号下拉菜单函数*/
function moreThingsOver(){
	moreThings=document.getElementById("dropdown-menu-plus");
	moreThings.style.display="block";
	moreThings.parentNode.children[0].firstChild.style.backgroundPositionY="-48px";
}
function moreThingOut(){
	moreThings.parentNode.style.background="none";
	moreThings.style.display="none";
	moreThings.parentNode.children[0].firstChild.style.backgroundPositionY="-32px";
}
function thingsOver(){
	moreThings.parentNode.style.background="#fff"
	moreThings.parentNode.children[0].firstChild.style.backgroundPositionY="-32px";
	for(var i=0;i<moreThings.children.length;i++){
		moreThings.children[i].onmouseover=function(){
			var $this=$(this);
			$this.children("a").children("i").stop().animate({
				backgroundPositionY:'-521px'
			},100);
		}
		moreThings.children[i].onmouseout=function(){
			var $this= $(this);
			$this.children("a").children("i").stop();
			$this.children("a").children("i").css("background-position-y","-501px");
		}
}
}

/*logo下拉列表函数*/
function logoOver(){
	logomenu=document.getElementById("dropdown-menu-logo");
	logomenu.parentNode.style.background="#fff";
	logomenu.style.display="block";
	logomenu.parentNode.children[0].firstChild.style.backgroundPositionY="-48px";
	logomenu.parentNode.children[0].lastChild.style.display="none";
}
function logoOut(){
	logomenu.parentNode.style.background="none";
	logomenu.style.display="none";
	logomenu.parentNode.children[0].firstChild.style.backgroundPositionY="-32px";
	logomenu.parentNode.children[0].lastChild.style.display="block";
}

/*左侧导航栏*/
function userSetting(){
  settings = document.getElementById("content-left");
	var items = settings.children;
	var l=items.length;
	for(var i=0;i<l;i++){
		items[i].onclick= function (){
			clearStyle1();
			this.children[0].className ="li-selected";
		}
	}
}
function clearStyle1(){
	for(var i=0;i<settings.children.length;i++){
		settings.children[i].children[0].className="";
	}
};

/*中间部分*/
function mainHeader(){
	main=document.getElementById("main-hd");
	for(var i=0;i<main.children.length;i++){
		main.children[i].onclick=function(){
			clearStyle2();
			this.className = "selected";
		}
	}
}
function clearStyle2(){
	for(var i=0;i<main.children.length;i++){
		main.children[i].className="";
	}
};
function bindingEmail(){
	document.getElementById("modal").style.display="block";
	document.getElementById("bindingEmail").style.display="block";
}
function bindingPhone(){
	document.getElementById("modal").style.display="block";
	document.getElementById("bindingPhone").style.display="block";	
}
function resetpassword(){
	document.getElementById("modal").style.display="block";
	document.getElementById("resetPassword").style.display="block";
}
function closeEmail(){
	document.getElementById("bindingEmail").style.display="none";
	document.getElementById("modal").style.display="none";
}
function closePhone(){
	document.getElementById("bindingPhone").style.display="none";
	document.getElementById("modal").style.display="none";
}
function closePassword(){
	document.getElementById("resetPassword").style.display="none";
	document.getElementById("modal").style.display="none";
}

function testEmail(obj){
	var filter  = /^([A-Za-z0-9]{3,16})+@([A-Za-z0-9]{2,3})+\.[A-Za-z]{2,14}$/;
	console.log(obj.value);
	if(filter.test(obj.value)){
		if($("#bindingEmail").css("display")=="block"){
			$("#emailWarning").text("");
		}
	}else{
		if(obj.value!==""){
			if($("#bindingEmail").css("display")=="block"){
				$("#emailWarning").text("邮箱格式有误！");
			}else{
				alert("邮箱格式有误！");
			}	
		}
	}
}
function testTelephone(obj){
	var filter=/^((13[0-9]{1})|159|153)+\d{8}$/;
	if(filter.test(obj.value)){
		if($("#bindingPhone").css("display")=="block"){
			$("#phoneWarning").text("");
		}
	}else{
		if(obj.value!==""){
			if($("#bindingPhone").css("display")=="block"){
				$("#phoneWarning").text("手机号码格式有误！");
			}else{
				alert("手机号码格式有误！");
			}		
		}
	}
}
